package com.genymobile.scrcpy.five.config;

import android.text.TextUtils;
import android.util.Log;

import com.genymobile.scrcpy.five.config.parser.AospEventMap;

public class EventMapFactory {
    private static final String TAG = EventMapFactory.class.getSimpleName();

    private static volatile IEventMap sEventMap = null;
    public static void init(String event2displayMapString) {
        Log.d(TAG, "init() " + event2displayMapString);
        if (!TextUtils.isEmpty(event2displayMapString)) {
            sEventMap = EventMapFromArgs.parse(event2displayMapString);
        }
        if (sEventMap == null) {
            // 没有传入 displayId和node的映射关系，尝试从getevent中解析
            sEventMap = InputDumpParser.parse();
        }
        Log.d(TAG, "sEventMap=" + (sEventMap != null ? sEventMap.getDisplay2EventNodeMap().toString() : null));
    }

    public static IEventMap getEventMap() {
        if (sEventMap != null) {
            return sEventMap;
        }
        return new AospEventMap();
    }
}
